import WeUniform from "./WeUniform"
import Cesium from "../Ces/Cesium"

export enum WeGridMovableStyle {
  Particles = 0,
  PolylineArrow = 1,
  PolylineOutline = 2,
  PolylineVolume = 3,
}

export type WeGridMovableOptions = {
  pointSize: number
  speed_factor: number
  numLon: number
  numLat: number
  drop_rate?: number
  drop_rate_bump?: number

  //style setting
  colorize?: boolean
  particleStyle?: WeGridMovableStyle

  //风向标
  iconOptions?: {
    repeatFactor?: number
    startLod?: number
    endLod?: number
  }

  //视野范围内粒子
  localViewOptions?: {
    scaler?: number
  }

  //3d wind
  offsetZ?: number // 偏移高度
  extrusion?: number // 拉伸高度
  zSpeedFactor?: number // w向量的速度比例
  extrusionAnimeHeight?: number //experiment

  //高级设置低空风场
  clipMinX?: number
  clipMaxX?: number
  clipMinY?: number
  clipMaxY?: number
  clipMinZ?: number
  clipMaxZ?: number

  bufferSize?: number
  numPointOfLine?: number

  //过滤风速
  limitMinZSpeed?: number //w向量的风速
  limitMaxSpeed?: number //uvw的风速
  limitMinSpeed?: number //uvw的风速
}

export const optionsToUniforms = (options: WeGridMovableOptions) => {
  const floatUniform = {
    numLon: options.numLon ?? 64,
    numLat: options.numLat ?? 64,
    meterWidth: 0,
    meterHeight: 0,
    pointSize: options.pointSize ?? 1,
    colorize: (options.colorize ?? false) ? 1.0 : 0.0,
    drop_rate: options.drop_rate ?? 0.01,
    drop_rate_bump: options.drop_rate_bump ?? 0.001,
    speed_factor: options.speed_factor ?? 1.0,
    dynamicPointSize: 1.0,
    dynamicSpeedFactor: 1.0,
    extrusion: options.extrusion ?? 1.0,
    extrusionAnimeHeight: options.extrusionAnimeHeight ?? 0.0,
    offsetZ: options.offsetZ ?? 0.0,
    clipMinX: options.clipMinX ?? 0.0,
    clipMaxX: options.clipMaxX ?? 1.0,
    clipMinY: options.clipMinY ?? 0.0,
    clipMaxY: options.clipMaxY ?? 1.0,
    clipMinZ: options.clipMinZ ?? 0.0,
    clipMaxZ: options.clipMaxZ ?? 1.0,
    useRTCenter: 0.0,
    bufferSize: options.bufferSize ?? 32,
    numPointOfLine: options.numPointOfLine ?? 6,
    showArrow: 0,
    limitMinSpeed: options.limitMinSpeed ?? 0.0,
    limitMaxSpeed: options.limitMaxSpeed ?? 10.0,
    limitMinZSpeed: options.limitMinZSpeed ?? -1.0,
    zSpeedFactor: options.zSpeedFactor ?? 1.0,

    particleStyle: options.particleStyle ?? WeGridMovableStyle.Particles,

    //后面处理
    particleSize: 1000,
  }

  const vec4Uniform = {
    viewExtent: Cesium.Rectangle.MAX_VALUE,
  }

  return new WeUniform({
    floatUniform,
    vec4Uniform,
    name: 'WeGridMovableUniforms',
  })
}

export default WeGridMovableStyle
